package com.zhuiyun.project.api.video.publishVideo.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.video.publishVideo.model.PublishVideoModel;
import com.zhuiyun.project.api.video.publishVideo.service.PublishVideoService;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName PublishVideoController
 * @Description 视频管理 用于对用户上传的视频进行增删改查
 * @Author qsh
 * @Date 2023/12/14 8:43
 **/
@RestController
@RequestMapping("/PublishVideo")
@Slf4j
public class PublishVideoController extends BaseController {
    @Autowired
    private PublishVideoService publishVideoService;

    /**
    * @Author qsh
    * @Description 分页查询未推荐视频
    * @Date 2023/12/14 8:51
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param publishVideoModel
    * @param pageRequest
    */
    @GetMapping("/getPublishVideo")
    @ApiOperation(value = "分页查询未推荐视频接口")
    @OptLog(modular = "运营视频管理", type = CommonConstants.SELECT, describe = "分页查询未推荐视频")
    public CommonResult getPublishVideo(PublishVideoModel publishVideoModel, PageRequest pageRequest){
        log.info("分页查询未推荐视频");
        return CommonResult.ok(publishVideoService.getPublishVideo(publishVideoModel,pageRequest));
    }

    /**
     * @Author qsh
     * @Description 分页查询已推荐视频
     * @Date 2023/12/14 8:51
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param publishVideoModel
     * @param pageRequest
     */
    @GetMapping("/getPublishVideoT")
    @ApiOperation(value = "分页查询未推荐视频接口")
    @OptLog(modular = "运营视频管理", type = CommonConstants.SELECT, describe = "分页查询已推荐视频")
    public CommonResult getPublishVideoT(PublishVideoModel publishVideoModel, PageRequest pageRequest){
        log.info("分页查询已推荐视频");
        return CommonResult.ok(publishVideoService.getPublishVideoT(publishVideoModel,pageRequest));
    }

    /**
     * @Author qsh
     * @Description 分页查询已下架视频
     *
     * @Date 2023/12/14 8:51
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param publishVideoModel
     * @param pageRequest
     */
    @GetMapping("/getPublishVideoX")
    @ApiOperation(value = "分页查询已下架视频接口")
    @OptLog(modular = "运营视频管理", type = CommonConstants.SELECT, describe = "分页查询已下架视频")
    public CommonResult getPublishVideoX(PublishVideoModel publishVideoModel, PageRequest pageRequest){
        log.info("分页查询已下架视频");
        return CommonResult.ok(publishVideoService.getPublishVideoX(publishVideoModel,pageRequest));
    }

    /**
    * @Author qsh
    * @Description 查看视频详情信息
    * @Date 2023/12/18 9:56
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param vId
* @param pageRequest
    */
    @GetMapping("/getPublishVideoById/{vId}")
    @ApiOperation(value = "查询视频详情接口")
    @OptLog(modular = "视频管理", type = CommonConstants.SELECT, describe = "查询视频详情")
    public CommonResult getPublishVideo(@PathVariable("vId") Integer vId, PageRequest pageRequest){
        log.info("查询视频详情");
        return CommonResult.ok(publishVideoService.getPublishVideoById(vId,pageRequest));
    }

    /**
    * @Author qsh
    * @Description 逻辑删除上传视频
    * @Date 2023/12/15 15:30
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param videoIds
    */
    @PutMapping("/deleteVideoById/{videoIds}")
    @ApiOperation(value = "逻辑删除上传视频接口")
    @OptLog(modular = "视频管理", type = CommonConstants.DELETE, describe = "逻辑删除上传视频")
    public CommonResult DeleteVideoId(@PathVariable("videoIds") List<Integer> videoIds) throws CommonException {
        log.info("逻辑删除上传视频");
        return publishVideoService.DeleteVideoById(videoIds);
    }

    /**
     * @Author qsh
     * @Description 绑定视频池（推荐、取消推荐
     * @Date 2023/12/15 15:30
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param videoIds
     */
    @PutMapping("/bindVideo/{videoIds}")
    @ApiOperation(value = "逻辑删除上传视频接口")
    @OptLog(modular = "视频管理", type = CommonConstants.DELETE, describe = "逻辑删除上传视频")
    public CommonResult BindVideo(@PathVariable("videoIds") List<Integer> videoIds) throws CommonException {
        log.info("逻辑删除上传视频");
        return publishVideoService.BindVideo(videoIds);
    }

    /**
    * @Author qsh
    * @Description 上传视频封面
    * @Date 2023/12/18 10:07
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param file
    */
    @PostMapping("/uploadVideoCover")
    @ApiOperation(value = "上传视频封面接口")
    @OptLog(modular = "视频管理", type = CommonConstants.ADD, describe = "上传视频封面")
    public CommonResult uploadVideoCover(@RequestParam MultipartFile file)throws CommonException {
        log.info("上传视频封面");
        return publishVideoService.uploadVideoCover(file);
    }

    /**
     * @Author qsh
     * @Description 上传视频
     * @Date 2023/12/18 10:07
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param file
     */
    @PostMapping("/uploadVideo")
    @ApiOperation(value = "上传视频接口")
    @OptLog(modular = "视频管理", type = CommonConstants.ADD, describe = "上传视频")
    public CommonResult uploadVideo(@RequestParam MultipartFile file)throws CommonException {
        log.info("上传视频");
        return publishVideoService.uploadVideoCover(file);
    }

    /**
    * @Author qsh
    * @Description 新增上传视频信息
    * @Date 2023/12/19 9:51
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param publishVideoModel
    */
    @PostMapping("/saveVideo")
    @ApiOperation(value = "新增视频接口")
    @OptLog(modular = "视频管理", type = CommonConstants.ADD, describe = "新增视频")
    public CommonResult saveVideo(@RequestBody PublishVideoModel publishVideoModel)throws CommonException {
        log.info("新增视频");
        return publishVideoService.saveVideo(publishVideoModel);
    }

    /**
    * @Author qsh
    * @Description 编辑上传视频信息
    * @Date 2023/12/21 9:10
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param publishVideoModel
    */
    @PutMapping("/updateVideo")
    @ApiOperation(value = "编辑视频接口")
    @OptLog(modular = "视频管理", type = CommonConstants.UPDATE, describe = "编辑视频")
    public CommonResult updateVideo(@RequestBody PublishVideoModel publishVideoModel)throws CommonException {
        log.info("编辑视频");
        return publishVideoService.updateVideo(publishVideoModel);
    }

    /**
    * @Author qsh
    * @Description 删除服务器视频
    * @Date 2023/12/25 15:41
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param id
    */
    @DeleteMapping("/deleteByVideoId/{id}")
    @ApiOperation(value = "删除服务器视频接口")
    @OptLog(modular = "视频管理", type = CommonConstants.UPDATE, describe = "删除服务器视频")
    public CommonResult deleteVideoById(@PathVariable("id") Integer id){
        return publishVideoService.deleteV(id);
    }

    /**
     * @Author qsh
     * @Description 删除服务器视频封面
     * @Date 2023/12/25 15:41
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param id
     */
    @DeleteMapping("/deleteVideoCoverById/{id}")
    @ApiOperation(value = "删除服务器视频接口")
    @OptLog(modular = "视频管理", type = CommonConstants.UPDATE, describe = "删除服务器视频")
    public CommonResult deleteVideoCoverById(@PathVariable("id") Integer id){
        return publishVideoService.deleteVC(id);
    }
}
